package fr.labri.macchiato.framework.business.sparql;

/**
 * 
 * @author Matthieu FOUCAULT
 *         <p>
 *         QueryBuilder is the base interface for any subclass able to build a
 *         query from a set of criteria
 *         </p>
 */
public interface QueryBuilder {

	/**
	 * Starts building a new query
	 */
	public void newQuery();

	/**
	 * Adds a prefix to the query, with the given name and value
	 * 
	 * @param name
	 * @param value
	 */
	public void addPrefix(String name, String value);

	/**
	 * Sets the variables in the select clause
	 * 
	 * @param fields
	 */
	public void setSelectFields(String... fields);

	/**
	 * adds an Order By clause to the query
	 * 
	 * @param field
	 * @param isAscOrder
	 */
	public void setOrderBy(String field, boolean isAscOrder);

	/**
	 * Adds a limit to the size of the query's result
	 * 
	 * @param limit
	 */
	public void setLimit(int limit);

	/**
	 * Adds a criterion to get all the entities of a type. <br>
	 * @param field
	 * @param type
	 */
	public void addTypeCriterion(String field, String type);

	/**
	 * Adds a regex filter to the request
	 * @param filteredVar
	 * @param regex
	 * @param flags
	 */
	public void addRegexFilter(String filteredVar, String regex, String flags);
	
	/**
	 * Start a new UNION clause
	 */
	public void beginUnionClauses();
	
	/**
	 * Add a clause to the UNION clauses
	 */
	public void addUnionClause();
	
	/**
	 * End an UNION clause
	 */
	public void endUnionClauses();

	/**
	 * @return the final query
	 */
	public String getQuery();

	/**
	 * Adds a criterion according to Sparql's triple pattern
	 * @param varName
	 * @param propertyName
	 * @param toVarName
	 */
	public void addPropertyCriterion(String varName, String propertyName,
			String toVarName);

}
